--1. Write your own “safe” definitions of the standard partial list functions, but make
--sure they never fail. As a hint, you might want to consider using the following types:
---- file: ch04/ch04.exercises.hs
--safeHead :: [a] -> Maybe a
--safeTail :: [a] -> Maybe [a]
--safeLast :: [a] -> Maybe a
--safeInit :: [a] -> Maybe [a]

safeHead :: [a] -> Maybe a
safeHead [] = Nothing
safeHead (x:xs) = Just x

safeTail :: [a] -> Maybe [a]
safeTail [] = Nothing
safeTail (x:xs) = Just xs

safeLast :: [a] -> Maybe a
safeLast [] = Nothing
safeLast list = Just (last list)

safeInit :: [a] -> Maybe [a]
safeInit [] = Nothing
safeInit list = Just (init list)


